﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Newtonsoft.Json;

namespace Meeting.Web.Admin
{
    /// <summary>
    /// LoginOperation 的摘要说明
    /// </summary>
    public class LoginOperation : IHttpHandler
    {
        string methodName = "";
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json;charset=utf-8";
            methodName = context.Request.Params["method"];

            switch (methodName)
            {
                case "IsLogin":
                     IsLogin(context) ;
                    break;

            }
        }

        private void IsLogin(HttpContext context)
        {
            BLL.Employee bll = new BLL.Employee();
            Model.JsonResponse jr = new Model.JsonResponse();
            jr.success = false;
            string user = context.Request["User"].ToString();
            string pass = context.Request["Pass"].ToString();
            if (user != "admin")
            {
                jr.Message = "不是管理员账号不能登录";

            }
            else
            {               
                DataSet ds = bll.GetList(" Account = '" + user + "' ");
                if (ds == null || ds.Tables[0].Rows.Count <1)
                {
                    jr.Message = "没有该账号的注册信息";
                }
                else
                {
                    if (ds.Tables[0].Rows[0]["PassWord"].ToString() != pass)
                    {
                        jr.Message = "密码错误";
                    }
                    else
                    {
                        jr.success = true;
                    }

                }
            }
            context.Response.Write(JsonConvert.SerializeObject(jr)); 

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}